home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d11 / ev678dev.arc / DAC.DOC < prev    next >
Text File  |  1990-07-03  |  5KB  |  145 lines

  1. -------------------------------------------------------------------------
  2. |            DAC.DOC                        |
  3. |    This document describes the process for loading the color     |
  4. |    registers of the video DAC and a sample code fragment.        |
  5. -------------------------------------------------------------------------
  6.  
  7. The DAC is only enabled when an analog monitor is attached.
  8.  
  9. The VGA's Digital-to-Analog Converter (DAC) contains an internal color
  10. lookup table to allow the user to select up to 256 colors from a palette of
  11. 262,144 possible colors.  The color look-up table is composed of 256 
  12. 18-bit color registers.  Each register is subdivided into 3 6-bit entries,
  13. where each entry is in the range 00h..3Fh.  These three values specify the
  14. red (R), green (G), and blue (B) intensities of the color register.  If R=G=B,
  15. the color register's output is a shade of gray.
  16.  
  17.         -------------------------
  18.         | 00h |  R  |  G  |  B  |
  19.         | 01h |  R  |  G  |  B  |
  20.         | 02h |  R  |  G  |  B  |
  21.         | 03h |  R  |  G  |  B  |
  22.         |  .  |  .  |  .  |  .  |
  23.         |  .  |  .  |  .  |  .  |
  24.         |  .  |  .  |  .  |  .  |
  25.         | FEh |  R  |  G  |  B  |
  26.         | FFh |  R  |  G  |  B  |
  27.         -------------------------
  28.  
  29.  
  30. For 256 color modes (IBM mode 13h, Everex Extended 256 color modes), all 256
  31. color registers are active.  For all other modes, you can select the paging
  32. mode and page# using IBM standard BIOS functions AX = 101Ah and AX = 1013h.
  33. The BIOS also provides functions for reading and writing the DAC color
  34. registers (AX = 1012h and AX = 1017h).  If you wish to program the DAC 
  35. directly, there are several steps to follow:
  36.  
  37.     1) Wait for vertical retrace. (This is not entirely necessary, but if
  38.        you write to the DAC when a retrace is not active, you will get
  39.        snow on the screen.)
  40.     2) Index the color register you want.
  41.     3) Output the R, G, and B values, in order.
  42.  
  43. Note: After writing the three color values, the color register index
  44.       will auto-increment to the next color register.  Also, you must insure
  45.       that there is a minimum 240 nanosecond delay between the output of each
  46.       color value.  This can easily be accomplished in assembly language by
  47.       inserting a jmp short $+2 between each out instruction.
  48.  
  49. A vertical retrace can be detected by reading the CRTC Stat port.  This
  50. port has address 3?Ah, where ? is D for color modes and B for monochrome
  51. modes.  A simple means of determining which value to use is to read the
  52. CRTC Addr port number from the BIOS data area at 0:463 (word).  This value
  53. will be either 3B4h or 3D4h.  Bit 3 of the byte read from the CRTC Stat port
  54. is 1 if a vertical retrace is active.  If you wish to prevent snow on the 
  55. screen, and you have a large block of color registers to output, you may wish
  56. to wait for the leading edge of the vertical retrace by first waiting for the
  57. retrace bit to go to 0, then waiting for the retrace bit to go to 1.  This
  58. will insure the maximum amount of time for outputting the block of color
  59. registers before the retrace ends.
  60.  
  61. The DAC Addr port number is 3C7h (W) for reading the DAC, and 3C8h (RW) for
  62. writing to the DAC.  The color values are written and read through port 3C9h 
  63. in the order of R, then G, then B.
  64.  
  65. To read back the values in the DAC, write the starting address to port
  66. 3C7h, then read successive triples from port 3C9h.
  67.  
  68. ; ************************************************************************
  69. ; ************************************************************************
  70.  
  71. mSysCrtcAddr    equ    463h        ; Offset to CRTC address in BIOS data
  72.  
  73. rDacAddrW    equ    3C8h        ; DAC Address port (Write mode)
  74. rDacData    equ    3C9h        ; DAC Data port
  75.  
  76. NumColors    equ    8        ; Program 8 color registers
  77. FirstReg    equ    0        ; First register to program
  78.  
  79. ColorTable    db    00h,00h,00h    ; Increasing intensities of gray
  80.         db    08h,08h,08h
  81.         db    10h,10h,10h
  82.         db    18h,18h,18h
  83.         db    20h,20h,20h
  84.         db    28h,28h,28h
  85.         db    30h,30h,30h
  86.         db    38h,38h,38h
  87.  
  88. ;    Wait for leading edge of vertical retrace first, to prevent snow
  89.  
  90.     xor    cx,cx            ; Maximum delay for waiting
  91.     mov    ds,cx
  92.     mov    dx,ds:[mSysCrtcAddr]    ; Get CRTC Addr
  93.     add    dx,6            ; Get CRTC Stat
  94. Wait1:
  95.     in    al,dx
  96.     test    al,8h            ; Check for retrace inactive
  97.     jz    RetraceInactive
  98.     loop    Wait1
  99.  
  100. ;    At this point a retrace is not occurring.  Now wait for leading edge
  101. ;    of next retrace.
  102.  
  103. RetraceInactive:
  104.     xor    cx,cx            ; Maximum delay for waiting
  105. Wait2:
  106.     in    al,dx
  107.     test    al,8h            ; Check for retrace active
  108.     jnz    RetraceActive
  109.     loop    Wait2
  110.  
  111. ;    A retrace should be just starting now, so set the DAC Write index
  112.  
  113. RetraceActive:
  114.     mov    dx,rDacAddrW        ; Get DAC write address
  115.     mov    al,FirstReg        ; First color register to program
  116.     out    dx,al            ; Set write index
  117.     jmp    short $+2        ; Insure sufficient delay
  118.  
  119. ;    DAC index set.  Now load up the color registers
  120.  
  121.     mov    dx,rDacData        ; Get DAC data address
  122.     mov    cx,NumColors        ; Number of color registers to program
  123.     lea    si,ColorTable        ; ds:si -> color table to load
  124.     push    cs
  125.     pop    ds
  126.  
  127. ProgramDACLoop:
  128.     lodsb                ; Get one Red color value
  129.     out    dx,al            ; Write it out
  130.     jmp    short $+2        ; Insure sufficient delay
  131.  
  132.     lodsb                ; Get one Green color value
  133.     out    dx,al            ; Write it out
  134.     jmp    short $+2        ; Insure sufficient delay
  135.  
  136.     lodsb                ; Get one Blue color value
  137.     out    dx,al            ; Write it out
  138.  
  139.     loop    ProgramDACLoop
  140.  
  141. ;    Color registers are now loaded
  142.  
  143. ; ************************************************************************
  144. ; ************************************************************************
  145.